<template>
  <a-table
    :data="tablists"
    :pagination="false"
    :loading="tableLoad"
    :bordered="{ wrapper: true, cell: tableBordered }"
    :stripe="(tableStriped as boolean)"
    :row-key="rowKey"
    :scroll="scroll"
    :scrollbar="{ type: 'track', outerClass: '', outerStyle: '' }"
  >
    <template #columns>
      <a-table-column
        v-for="item of tableColumns.list"
        :key="item.key"
        align="left"
        :width="item.width"
        :title="(item.title as string)"
        :data-index="(item.key as string)"
        :ellipsis="true"
        :tooltip="true"
    /></template>
  </a-table>
</template>

<script lang="ts">
  import { useRowKey, useTable } from '@/hooks/table'
  import { defineComponent, reactive, ref, toRef, watch } from 'vue'
  export default defineComponent({
    name: 'CardNo',
    props: {
      tablist: {
        type: Array,
        require: true,
      },
      load: {
        type: Boolean,
        require: true,
      },
    },
    setup(props) {
      const scroll = {
        x: 1500,
      }
      const tempTableProps = toRef(props, 'tablist')
      const tempTablePropsLoad = toRef(props, 'load')
      const rowKey = useRowKey('id')
      const table = useTable()
      const tableLoad = ref(true)
      const tableBordered = ref(false)
      const tableStriped = ref(false)
      const tablists: any = ref([])
      const tableColumns: any = reactive({
        list: [
          {
            title: '接口卡号',
            key: 'apiCard',
            dataIndex: 'apiCard',
            align: 'center',
            checked: true,
          },
          {
            title: '完整卡号',
            key: 'iccid',
            dataIndex: 'iccid',
            align: 'center',
            checked: true,
          },
          {
            title: '显示卡号',
            key: 'card',
            dataIndex: 'card',
            align: 'center',
            checked: true,
          },
          {
            title: '实名卡号',
            key: 'realNameCard',
            dataIndex: 'realNameCard',
            align: 'center',
            checked: true,
          },
          {
            title: 'IMEI',
            key: 'imei',
            dataIndex: 'imei',
            align: 'center',
            checked: true,
          },
          {
            title: 'IMSI',
            key: 'imsi',
            dataIndex: 'imsi',
            align: 'center',
            checked: true,
          },
        ],
      })

      watch([() => tempTablePropsLoad.value, () => tempTableProps.value], (oldVal) => {
        tableLoad.value = oldVal[0]
        tablists.value = oldVal[1]
      })
      return {
        rowKey,
        tableColumns,
        table,
        tablists,
        tableLoad,
        tableBordered,
        tableStriped,
        scroll,
      }
    },
  })
</script>

<style lang="less" scoped></style>
